package com.cskaoyan.service;

import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.bean.MarketBrandExample;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author gatsby
 * @since 2022/10/14 16:34
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    /**
     * 分页查询品牌的业务逻辑
     *
     * @return com.cskaoyan.bean.common.CommonData<com.cskaoyan.bean.MarketBrand>
     * @author gatsby
     * @since 2022/10/14 16:45
     */
    @Override
    public CommonData<MarketBrand> queryAllBrandLimit(BasePageInfo basePageInfo) {

        //开启分页
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketBrandExample example = new MarketBrandExample();
        example.setDistinct(true);
        MarketBrandExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(example);
        PageInfo<MarketBrand> pageInfo = new PageInfo<>(marketBrands);
        return CommonData.data(pageInfo);
    }

    /**
     * 查询商品品牌的业务逻辑
     *
     * @param id
     * @return com.cskaoyan.bean.MarketBrand
     * @author gatsby
     * @since 2022/10/14 17:42
     */
    @Override
    public MarketBrand queryBrandDetail(Integer id) {
        MarketBrandExample example = new MarketBrandExample();
        example.setDistinct(true);
        MarketBrandExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        criteria.andIdEqualTo(id);

        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(example);

        return marketBrands.get(0);

    }
}
